<template>
	<view class="wrap">
		<cp-list 
			:cpList="cpList"
			@goDet="goCpDet"
		></cp-list>
		<loading-view :loading="loading"></loading-view>
	</view>
</template>

<script>
	import CpList from '../../index/components/CpList.vue'
	import { getZzIndexSliceCpList } from '@/api/index/index'
	export default {
		components:{
			CpList
		},
		data(){
			return{
				cpList:[],
				nowPage:1,
				loading:false,
				isHasDataFlag:null,
				hasNextFlag:null
			}
		},
		onLoad(){
			this.getList();
		},
		onPullDownRefresh : function(){
			this.initParams();
			uni.stopPullDownRefresh();
		},
		onReachBottom : function(){
			if( !this.loading && this.hasNextFlag ){
				this.getList();
			}
		},
		methods:{
			getList(){
				let { nowPage,cpList } = this;
				this.loading = true;
				var field = {page:this.nowPage,limit:this.limit };
				getZzIndexSliceCpList(field).then(res=>{
					//console.log(res)
					this.hasNextFlag = res.data.hasNext;
					nowPage += 1;
					cpList.push( ...res.data.datas );
					this.cpList = cpList;
					this.nowPage = nowPage;
					this.loading = false;
					this.isHasDataFlag = true;
				}).catch(err=>{
					//console.log(err)
					this.loading = false;
					this.isHasDataFlag=false;
				});
			},
			initParams(){
				this.nowPage = 1;
				this.loading = false;
				this.cpList = [];
				this.getList();
			},
			goCpDet(item){
				uni.navigateTo({
					url:'/pages/subIndex/cpDet/cpDet?orderId=' + item.orderId
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.wrap{
		padding-top: 30rpx;
	}
</style>